<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>题库添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/lib/layui-v2.6.8/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/css/public.css" media="all">
    <link rel="stylesheet" href="/static/css/xadmin.css">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <form id="myadd" class="layui-form layui-form-pane" lay-submit
          lay-filter="userForm" enctype="multipart/form-data">

        <div class="layui-form-item">
            <label class="layui-form-label"><span class="x-red">*</span>题目类别</label>
            <div class="layui-input-block">
                <input type="radio" name="major" value="Java" lay-skin="primary" title="Java" checked="">
                <input type="radio" name="major" value="HTML5" lay-skin="primary" title="HTML5">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="x-red">*</span>题目级别</label>
            <div class="layui-input-block">
                <input type="radio" name="level" value="1" lay-skin="primary" title="简单" checked="">
                <input type="radio" name="level" value="2" lay-skin="primary" title="普通">
                <input type="radio" name="level" value="3" lay-skin="primary" title="困难">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">题目类型</label>
            <div class="layui-input-block">
                <input type="text" name="seg" style="width: 60%;"  placeholder="请输入考试题目类型" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="clazz" class="layui-form-label">
               团队
            </label>
            <div class="layui-col-md6 layui-input-inline" style="width: 55%;">
                <select name="clazzId" id="clazz" >

                </select>
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label required">单选题分值</label>
            <div class="layui-input-block">
                <input type="text" id="chooseScore" name="chooseScore" style="width: 60%" placeholder="请输入单选题分值" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">单选题总数</label>
            <div class="layui-input-block">
                <input type="text" id="chooseSum" name="chooseSum" style="width: 60% ;border:solid 1px greenyellow" placeholder="请输入单选题总数" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">代码题分值</label>
            <div class="layui-input-block">
                <input type="text" id="codeScore" name="codeScore" style="width: 60%" placeholder="请输入代码题分值" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">代码题总数</label>
            <div class="layui-input-block">
                <input type="text" id="codeSum" name="codeSum" style="width: 60% ;border:solid 1px greenyellow" placeholder="请输入代码题总数" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">判断题分值</label>
            <div class="layui-input-block">
                <input type="text" style="width: 60%" id="judgeScore" name="judgeScore" placeholder="请输入判断题分值" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">判断题总数</label>
            <div class="layui-input-block">
                <input type="text" style="width: 60% ;border:solid 1px greenyellow" id="judgeSum" name="judgeSum" placeholder="请输入判断题总数" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">主观题分值</label>
            <div class="layui-input-block">
                <input type="text" id="subjectiveScore" name="subjectiveScore" style="width: 60%" placeholder="请输入主观题分值" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" >
            <label class="layui-form-label required">主观题总数</label>
            <div class="layui-input-block">
                <input type="text" id="subjectiveSum" name="subjectiveSum" style="width: 60% ;border:solid 1px greenyellow" placeholder="请输入主观题总数" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button id="save" type="button" class="layui-btn" lay-submit lay-filter="formUser">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>

<script src="/static/lib/layui-v2.6.8/layui.js" charset="utf-8"></script>
<script src="/static/js/jquery.min.js"></script>
<script>
    function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return 1;
    }


    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;


        var  perid = getUrlParam("perid");
        console.log( perid)
        // 填充团队信息
        $.ajax({
            type:"post",
            url:"/clazz/queryAllClazz",
            data: {"perid":perid},
            success: function (res) {
                var content=" <option value=\"\">请选择团队</option>";
                for (var i = 0; i < res.data.length; i++) {
                    content+="<option value='"+res.data[i].id+"'>"+res.data[i].clazzName+"</option>";
                }
                $("#clazz").html(content);
                console.log(content);
                form.render('select');
            }
        })


        //监听提交
        form.on('submit(formUser)', function (data) {
            data.field.perid = getUrlParam("perid");
            // console.log(data.field)
            $.ajax({
                url: '/exam1/examAdd',
                data: data.field,
                type: "post",
                success: function (res) {
                    if (res.status==0){
                        alert("添加考试成功")
                        //重新加载父页面
                        parent.location.reload();

                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                    }else if (res.status == 1) {
                        alert("添加失败（请检查分值或题目数）");
                    }
                },
                errors:function (res){
                    if (res.status == 1) {
                        alert("添加失败（请检查分值或题目数）");
                    }
                }
            })
            return false;
        });
    });
</script>
</body>
</html>